﻿/*-----------------------------------------------------------------------
 * <copyright file="ParentIDQuery.xaml.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang jun</author>
 * <summary>
 *             ParentID 信息查询
 * 
 *          作成日：06/29/2011
 *          
 * </summary>
 *----------------------------------------------------------------------- 
 */
namespace Orid.Management.Statistics.OperatorUnitMangement.TheOthersRelated.ParentIDQuery
{
    using System;
    using System.Text;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Media;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.FunctionList;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.Window;
    using Orid.Management.Statistics.OperatorUnitMangement.WCFServers.OthersQueryRef;
    using childWindow = Orid.Management.Statistics.OperatorUnitMangement.Common.Window;
    using Wcf = Orid.Management.Statistics.OperatorUnitMangement.Common.Service;


    public partial class ParentIDContainter : UserControl
    {
        #region 全局变量
        /// <summary>
        /// 当前查询框的名字（日志用）
        /// </summary>
        private string ctrlName = " ParentID 信息查询";

        /// <summary>
        /// 查询子窗体 lineSelectWin
        /// </summary>
        childWindow.LineSelChildWin lineSelect = null;

        /// <summary>
        /// 消息子窗体 errorMessbox
        /// </summary>
        private childWindow.MessageBox errorMessbox = null;

        /// <summary>
        /// 日志服务定义
        /// wcfLogClient
        /// </summary>
        private WCFLog4Ref.WCFLog4Client wcfLogClient = null;

        /// <summary>
        /// ParentID 信息查询
        /// </summary>
        private WCFTheOthersQueryClient wcfParentIDQueryClient = null;

        /// <summary>
        /// 分页控件
        /// PagedCollectionView
        /// </summary>
        private PagedCollectionView pcv;
        
        /// <summary>
        /// 记录要导出的数据
        /// </summary>
        DataGrid dataToCSV;
        
        /// <summary>
        /// 用户选择条件日志
        /// </summary>
        string whereInforLogs;
        /// <summary>
        /// 记录用户查询条件
        /// </summary>
        /// <value>10/15/2010 Add</value>
        public string WhereInforLogs
        {
            get;
            set;
        }

        /// <summary>
        /// 记录总数
        /// </summary>
        private int sumRecordCount = 0;

        /// <summary>
        /// 记录NumericUpDown分页数
        /// </summary>
        private double oldNumericUpDown = 0;


        /// <summary>
        /// 案件名查询子窗体 matterIDSelect
        /// </summary>
        childWindow.MatterNameSelChildWin matterIDSelect = null;


        /// <summary>
        /// UserOrder客户种类查询子窗体
        /// </summary>
        childWindow.UserOrderChildWin userOrderSelect = null;

        #endregion 全局变量

        public ParentIDContainter()
        {
            InitializeComponent();

            // 引用主题
            ((App)Application.Current).SetTheme(this);

            this.InitField();

            this.dgParentsIDQuery.HeadersVisibility = DataGridHeadersVisibility.All;//同时显示DataGrid的行头与列头

            //查询按钮
            this.btnSelList.Click+=new RoutedEventHandler(btnSelList_Click);

            // ParientID查询 委托
            this.wcfParentIDQueryClient.SelectParentIDInforCompleted+=new EventHandler<SelectParentIDInforCompletedEventArgs>(wcfParentIDQueryClient_SelectParentIDInforCompleted);
            
            //数据 导出（只有SSV或SQC可用此功能）
            this.btnExport.Click += new RoutedEventHandler(btnExport_Click);

            //页面载入
            this.Loaded += new RoutedEventHandler(ParentIDContainter_Loaded);
           
            //... 按钮，显示LINE窗体
            this.btnSelContext.Click += new RoutedEventHandler(btnSelContext_Click);
            // LINE子窗体关闭
            this.lineSelect.Closed += new EventHandler(lineSelect_Closed);

            // ... 按钮，显示账票ID查询子窗体
            this.btnMatterID.Click += new RoutedEventHandler(btnMatterID_Click);
            // 账票ID查询子窗体关闭
            this.matterIDSelect.Closed += new EventHandler(matterNameSelect_Closed);

            // ... 按钮，显示 UserOrder 客户种类 查询子窗体
            this.btnUserOrderID.Click += new RoutedEventHandler(btnUserOrderID_Click);
            // UserOrder 客户种类查询子窗体关闭
            this.userOrderSelect.Closed += new EventHandler(userOrderSelect_Closed);

            //查询按钮可用
            this.btnSelList.IsEnabled = true;
        }


        #region 变量初始化方法  InitField
        /// <summary>
        /// 变量初始化方法  InitField
        /// </summary>
        private void InitField()
        {
            this.lineSelect = new LineSelChildWin();
            this.matterIDSelect = new MatterNameSelChildWin(MatterShape.MatterID.ToString(), MatterShape.MatterValue.ToString());
            this.userOrderSelect = new UserOrderChildWin();

            this.errorMessbox = new childWindow.MessageBox();
            this.wcfLogClient = Wcf.Service.Log4;
            this.wcfParentIDQueryClient = Wcf.Service.TheParentIDInfoQuery;
            this.whereInforLogs = string.Empty;
           
        }
        #endregion 变量初始化方法  InitField

        #region 页面载入
        /// <summary>
        /// 页面载入
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        void ParentIDContainter_Loaded(object sender, RoutedEventArgs e)
        {
             //只有SSV或SQC可用使用 数据导出 功能
             //(如果当前用户不是 SV或QC 显示 数据导出 功能)
            if (!(ClientUserInfor.RoleName.ToUpper().Trim().Equals("SV") || ClientUserInfor.RoleName.ToUpper().Trim().Equals("QC")))
            {
                this.btnExport.Visibility = Visibility.Visible;
            }

            this.dpDateFrom.SelectedDate = DateTime.Now.AddDays(-1);

            this.dpDateTo.SelectedDate = DateTime.Now.Date;

            this.btnSelList.IsEnabled = true;

            this.nuPageSize.IsEnabled = true;//分页数控制

        }
        #endregion  页面载入

        #region  查询相关
        /// <summary>
        /// 查询按钮
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnSelList_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // 记录用户选择的WHERE条件
                writeWhereLog();
                
                // 条件约束
                // this.tbOPID.Text dpDateFrom 内容必选的判断
                // 日期不能相同
                // 开始日期不能小于结束日期            
                int error = FunctionClass.IsSelectDo(
                                                        this.dpDateFrom,
                                                        this.dpDateTo,
                                                        this.errorMessbox);
                if (error == 0)
                {
                    this.btnSelContext.IsEnabled = true;
                    return;
                }


                // 传送到服务端的参数列表
                WCFServers.OthersQueryRef.WhereParameters fitWhereData = new WhereParameters();

                // 日期的判断条件
                // 日期返回空值用"null"
                if (!String.IsNullOrEmpty(this.dpDateFrom.Text))
                {
                    fitWhereData.WhereentryDateFrom = this.dpDateFrom.SelectedDate.Value.ToString("yyyy-MM-dd");
                }
                else
                {
                    fitWhereData.WhereentryDateFrom = "null";
                }

                if (!String.IsNullOrEmpty(this.dpDateTo.Text))
                {
                    fitWhereData.WhereentryDateTo = this.dpDateTo.SelectedDate.Value.ToString("yyyy-MM-dd");
                }
                else
                {
                    fitWhereData.WhereentryDateTo = "null";
                }


                // 如果选 LINE 方式查询
                if (ClientDataList.SelLineList.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in ClientDataList.SelLineList)
                    {
                        // 添加逗号
                        sb.Append(s + ",");
                    }

                    // 去除尾部多余逗号
                    fitWhereData.WhereServer = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                }

                // 帐票ID选择条件 
                if (ClientDataList.SelMatterNamesList.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in ClientDataList.SelMatterNamesList)
                    {
                        // 添加逗号
                        sb.Append(s + ",");
                    }

                    // 去除尾部多余逗号
                    fitWhereData.WhereOpID = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                }

                // 客户种类
                if (ClientDataList.SelUserOrderList.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in ClientDataList.SelUserOrderList)
                    {
                        // 添加逗号
                        sb.Append(s + ",");
                    }

                    // 去除尾部多余逗号
                    fitWhereData.WhereUnit = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                }

                SetBusyBar(1000);

                //调用 OP 权限查询 
                this.wcfParentIDQueryClient.SelectParentIDInforAsync(fitWhereData);

                //查询按钮不可用
                this.btnSelList.IsEnabled = false;
                this.nuPageSize.IsEnabled = false;//分页数控制

            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                                ctrlName +
                                                                ex.Message.ToString() +
                                                                this.WhereInforLogs);

                this.nuPageSize.IsEnabled = true;//分页数控制
                //查询按钮可用
                this.btnSelList.IsEnabled = true;

                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        /// <summary>
        /// ParientID查询委托实现
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Orid.Management.Statistics.OperatorUnitMangement.WCFServers.OthersQueryRef.SelectParentIDInforCompletedEventArgs"/> instance containing the event data.</param>
        void wcfParentIDQueryClient_SelectParentIDInforCompleted(object sender, SelectParentIDInforCompletedEventArgs e)
        {
            try
            {
                //设置 查询界面 的 查询按钮 可用
                this.btnSelList.IsEnabled = true;

                if (e.Error == null)
                {
                    if (e.Result.Count > 0)
                    {
                        //记录所查询的记录总数（导出结果与排序内容一致用）
                        this.sumRecordCount = e.Result.Count;

                        this.pcv = new PagedCollectionView(e.Result);
                        this.pcv.PageSize = Convert.ToInt32(this.nuPageSize.Value);

                        this.dgParentsIDQuery.ItemsSource = null;
                        this.dgParentsIDQuery.ItemsSource = this.pcv;

                        this.dpDataPage.DataContext = null;
                        this.dpDataPage.DataContext = this.pcv;

                        //数据导出
                        this.dataToCSV = new DataGrid();
                        this.dataToCSV.ItemsSource = e.Result;

                        Dispatcher.BeginInvoke(() => DataContext = false);
                        this.nuPageSize.IsEnabled = true; //控制分页数量 09/28/2010 Add


                        this.wcfLogClient.InfoAsync(((App)Application.Current).LogStr +
                                                        "在 " + this.ctrlName + "查询中查询记录" +
                                                        this.WhereInforLogs);
                    }
                    else
                    {
                        this.dgParentsIDQuery.ItemsSource = null;
                        this.dpDataPage.DataContext = null;
                        this.dataToCSV.ItemsSource = null;

                        throw new Exception(this.ctrlName + " 没有可显示的数据 ");
                    }
                }
                else
                {
                    throw new Exception("SelectParentIDInforCompleted服务返回值有错" + e.Error.Message.ToString());
                }
            }
            catch (Exception exce)
            {
                string exceptionStr = FunctionClass.GetMessageInformation(exce);

                Dispatcher.BeginInvoke(() => DataContext = false);
                this.nuPageSize.IsEnabled = true; //分页数量 

                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                                    ctrlName +
                                                                    exceptionStr +
                                                                    this.WhereInforLogs);
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   exceptionStr,
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion  查询相关

        #region 数据导出
        /// <summary>
        /// 数据导出
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        void btnExport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.dgParentsIDQuery.ItemsSource == null)
                {
                    throw (new Exception("请查询后再将数据导出。"));
                }
                else
                {
                    //记录导出前分页数，导出后还原。
                    //让导出的数据每页记录数为所有记录总数，导出数据为排序后的结果
                    this.oldNumericUpDown = this.nuPageSize.Value;
                    this.pcv.PageSize = this.sumRecordCount;
                    this.dataToCSV.ItemsSource = this.pcv;

                    //dgOPRolesDataExport 取表头的数据源
                    ExportDataToFile(this.dgParentsIDQuery);
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                ctrlName +
                                                ex.Message.ToString() +
                                                this.WhereInforLogs);

                Common.FunctionList.FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }
        /// <summary>
        /// 数据导出
        /// </summary>
        /// <param name="grid"></param>
        private void ExportDataToFile(DataGrid grid)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.DefaultExt = "csv";
                sfd.Filter = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*";

                sfd.FilterIndex = 1;
                bool? ret = sfd.ShowDialog();
                if (ret == true)
                {
                    string data = Orid.Management.Statistics.OperatorUnitMangement.Common.Export.DataExport.ExportDataGrid(true, grid, dataToCSV, null);

                    using (System.IO.Stream stream = sfd.OpenFile())
                    {
                        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, System.Text.UnicodeEncoding.Unicode))
                        {

                            data = data.Replace("^", "\t");
                            writer.Write(data);
                            writer.Close();
                        }
                        stream.Close();
                    }

                    this.pcv.PageSize = Convert.ToInt32(this.oldNumericUpDown);

                    this.wcfLogClient.InfoAsync(((App)Application.Current).LogStr +
                                                    " 在 " + this.ctrlName + " 中导出记录" +
                                                    this.WhereInforLogs);

                    Common.FunctionList.FunctionClass.ShowMessageBox(
                       this.errorMessbox,
                       0,
                       "提示",
                       "数据已导出。",
                       Colors.Gray,
                       true,
                       Visibility.Visible,
                       Visibility.Collapsed);
                    return;
                }
                else
                {
                    this.pcv.PageSize = Convert.ToInt32(this.oldNumericUpDown);
                    return;
                }
            }
            catch (Exception ex)
            {
                this.pcv.PageSize = Convert.ToInt32(this.oldNumericUpDown);

                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                    ctrlName +
                                                    ex.Message.ToString() +
                                                    this.WhereInforLogs);

                Common.FunctionList.FunctionClass.ShowMessageBox(
                      this.errorMessbox,
                      1,
                      "提示",
                      ex.Message.ToString(),
                      Colors.Gray,
                      true,
                      Visibility.Visible,
                      Visibility.Collapsed);

                return;
            }

        }
        #endregion 数据导出

        #region BusyBar
        /// <summary>
        /// 让BusyBar开始
        /// SetBusyBar
        /// </summary>
        /// <param name="busySeconds">busy秒数 busysecond</param>
        public void SetBusyBar(int busySeconds)
        {
            int delayMilliseconds = 2;
            biBusyBar.DisplayAfter = TimeSpan.FromMilliseconds(delayMilliseconds);

            DataContext = true;

            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(busySeconds * 1000);
            });
        }
        #endregion BusyBar

        #region 线路查询子窗体
        /// <summary>
        ///  ... 按钮，显示LINE窗体
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnSelContext_Click(object sender, RoutedEventArgs e)
        {
            this.lineSelect.Title = "线路查询子窗体";
            this.lineSelect.Show();
        }

        /// <summary>
        /// LINE子窗体关闭
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The  instance containing the event data.</param>
        void lineSelect_Closed(object sender, EventArgs e)
        {
            try
            {
                this.lineSelect = sender as childWindow.LineSelChildWin;

                if (this.lineSelect.DialogResult == true)
                {
                    //将LINE记录值添加逗号(多值时-用于界面上的TEXT中显示值)
                    if (ClientDataList.SelLineList.Count > 0)
                    {
                        #region 多值时,添加逗号
                        StringBuilder sb = new StringBuilder();
                        foreach (string str in ClientDataList.SelLineList)
                        {
                            sb.Append(str + ",");
                        }

                        this.tbSelContext.Text = string.Empty;

                        // 去除尾部多余逗号
                        this.tbSelContext.Text = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                        #endregion 多值时,添加逗号

                        this.tbSelContext.Text = string.Empty;
                        this.tbSelContext.Text = this.lineSelect.retRadioButtonContent.ToString();
                        return;
                    }
                    //取消所有选择时或是没有选择时，清空文本
                    else
                    {
                        this.tbSelContext.Text = string.Empty;
                    }
                }

                if (this.lineSelect.DialogResult == false)
                {
                    //当按取消按钮时，清空文本 v2.14
                    this.tbSelContext.Text = string.Empty;

                    return;
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                ctrlName +
                                                " lineSelectWin_Closed 转换Line信息时出错" +
                                                ex.Message.ToString());
                // 查询按钮
                this.btnSelList.IsEnabled = true;

                Common.FunctionList.FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion 线路查询子窗体

        #region 账票ID查询子窗体

        /// <summary>
        /// ... 按钮，显示账票ID查询子窗体
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnMatterID_Click(object sender, RoutedEventArgs e)
        {
            this.matterIDSelect.Title = "账票ID查询子窗体";
            this.matterIDSelect.Show();
        }

        /// <summary>
        ///  账票ID查询子窗体关闭事件
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The  instance containing the event data.</param>
        void matterNameSelect_Closed(object sender, EventArgs e)
        {
            try
            {
                this.matterIDSelect = sender as childWindow.MatterNameSelChildWin;

                if (this.matterIDSelect.DialogResult == true)
                {
                    //将LINE记录值添加逗号(多值时-用于界面上的TEXT中显示值)
                    if (ClientDataList.SelMatterNamesList.Count > 0)
                    {
                        #region 多值时,添加逗号
                        StringBuilder sb = new StringBuilder();
                        foreach (string str in ClientDataList.SelMatterNamesList)
                        {
                            sb.Append(str + ",");
                        }

                        this.tbMatterID.Text = string.Empty;

                        // 去除尾部多余逗号
                        this.tbMatterID.Text = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                        #endregion 多值时,添加逗号

                        this.tbMatterID.Text = string.Empty;
                        this.tbMatterID.Text = this.matterIDSelect.retRadioButtonContent.ToString();
                        return;
                    }
                    //取消所有选择时或是没有选择时，清空文本
                    else
                    {
                        this.tbMatterID.Text = string.Empty;
                    }
                }

                if (this.matterIDSelect.DialogResult == false)
                {
                    //当按取消按钮时，清空文本 v2.14
                    this.tbMatterID.Text = string.Empty;
                    return;
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                ctrlName +
                                                " matterNameSelectWin_Closed 转换案件名信息时出错" +
                                                ex.Message.ToString());

                this.btnSelList.IsEnabled = true;

                Common.FunctionList.FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion 账票ID查询子窗体

        #region UserOrder 客户种类 查询子窗体

        /// <summary>
        /// ... 按钮，显示 UserOrder 客户种类 查询子窗体
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnUserOrderID_Click(object sender, RoutedEventArgs e)
        {
            this.userOrderSelect.Title = "客户种类查询子窗体";
            this.userOrderSelect.Show();
        }

        /// <summary>
        ///  UserOrder 客户种类查询子窗体关闭
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The  instance containing the event data.</param>
        void userOrderSelect_Closed(object sender, EventArgs e)
        {
            try
            {
                this.userOrderSelect = sender as childWindow.UserOrderChildWin;

                if (this.userOrderSelect.DialogResult == true)
                {
                    //将LINE记录值添加逗号(多值时-用于界面上的TEXT中显示值)
                    if (ClientDataList.SelUserOrderList.Count > 0)
                    {
                        #region 多值时,添加逗号
                        StringBuilder sb = new StringBuilder();
                        foreach (string str in ClientDataList.SelUserOrderList)
                        {
                            sb.Append(str + ",");
                        }

                        this.tbUserOrderID.Text = string.Empty;

                        // 去除尾部多余逗号
                        this.tbUserOrderID.Text = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                        #endregion 多值时,添加逗号

                        this.tbUserOrderID.Text = string.Empty;
                        this.tbUserOrderID.Text = this.userOrderSelect.retRadioButtonContent.ToString();
                        return;
                    }
                    //取消所有选择时或是没有选择时，清空文本
                    else
                    {
                        this.tbUserOrderID.Text = string.Empty;
                    }
                }

                if (this.userOrderSelect.DialogResult == false)
                {
                    //当按取消按钮时，清空文本 v2.14
                    this.tbUserOrderID.Text = string.Empty;
                    return;
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                ctrlName +
                                                " userOrderSelect_Closed 转换案件名信息时出错" +
                                                ex.Message.ToString());

                this.btnSelList.IsEnabled = true;

                Common.FunctionList.FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion UserOrder 客户种类 查询子窗体

        #region 日期(DatePicker)
        /// <summary>
        /// 结束日期(DatePicker)
        /// DpDateTo_SelectedDateChanged
        /// </summary>
        /// <param name="sender">sender of obejct</param>
        /// <param name="e">e type of SelectionChangedEventArgs</param>
        private void DpDateTo_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dpDateTo == null || dpDateTo.SelectedDate == null)
            {
                return;
            }
            else
            {
                this.dpDateTo.Text = this.dpDateTo.SelectedDate.Value.ToString("yyyy-MM-dd");
            }
        }

        /// <summary>
        /// 开始日期(DatePicker)
        /// 防止选错时，出现BUG
        /// </summary>
        /// <param name="sender">sender of object</param>
        /// <param name="e">e type of SelectionChangedEventArgs</param>
        private void DpDateFrom_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dpDateFrom == null || dpDateFrom.SelectedDate == null)
            {
                return;
            }
            else
            {
                this.dpDateFrom.Text = this.dpDateFrom.SelectedDate.Value.ToString("yyyy-MM-dd");
            }
        }

        #endregion 日期(DatePicker)

        #region 记录用户选择的WHERE条件
        /// <summary>
        /// 记录用户选择的WHERE条件
        /// </summary>
        /// <returns></returns>
        private void writeWhereLog()
        {
            StringBuilder sbWhereIntorLogs = new StringBuilder();
            try
            {
                //日志用
                sbWhereIntorLogs.Append(" 查询条件：");
                sbWhereIntorLogs.Append(" 开始日期：");
                sbWhereIntorLogs.Append(string.IsNullOrEmpty(this.dpDateFrom.Text) == true ? " null" : this.dpDateFrom.Text);
                sbWhereIntorLogs.Append(" 结束日期：");
                sbWhereIntorLogs.Append(string.IsNullOrEmpty(this.dpDateTo.Text) == true ? " null" : this.dpDateTo.Text);
                
                sbWhereIntorLogs.Append(" 帐票ID：");
                sbWhereIntorLogs.Append(string.IsNullOrEmpty(this.tbMatterID.Text) == true ? " null" : this.tbMatterID.Text);
                sbWhereIntorLogs.Append(" 客户种类：");
                sbWhereIntorLogs.Append(string.IsNullOrEmpty(this.tbUserOrderID.Text) == true ? " null" : this.tbUserOrderID.Text);

                sbWhereIntorLogs.Append(" 线路：");
                sbWhereIntorLogs.Append(string.IsNullOrEmpty(this.tbSelContext.Text) == true ? " null" : this.tbSelContext.Text);

            }
            catch
            {
                WhereInforLogs = string.Empty;
            }

            WhereInforLogs = sbWhereIntorLogs.ToString();
        }

        #endregion 记录用户选择的WHERE条件

    }
}
